package com.campus.delivery.config;

import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Bean
	public Docket createRestApi() {
		String tokenstr = "6cd1d62abe5e35315f2ac1332524a3a5f09bf7743ce492914f801ffd46c31fcf";
		ParameterBuilder tokenParameterBuilder = new ParameterBuilder();

		tokenParameterBuilder.name("token").defaultValue(tokenstr).description("用户token")
				.modelRef(new ModelRef("string")).parameterType("header").required(false).build();

		List<Parameter> addParameters = Lists.newArrayList();
		addParameters.add(tokenParameterBuilder.build());
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.globalOperationParameters(addParameters)
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.campus.delivery.controller"))
				.paths(PathSelectors.any()).build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("青理乐送App端Api接口文档").description("青理乐送App端Api接口文档").version("1.0").build();
	}
}
